package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.ex.ServiceException;
import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.AlbumUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumListItemVO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

/**
 * ClassName: AlbumController
 * Package: cn.tedu.csmall.product.controller
 * Description
 *
 * @version 0.0.1
 * @Author: 大傻
 * @Create:2022/11/29
 */
@Api(tags = "03. 相册管理模块")
@RestController
@RequestMapping("/albums")
@Validated
@Slf4j
public class AlbumController {
    @Autowired
    private IAlbumService albumService;
    //http://localhost:9080/albums/add-new
    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew( @Valid  AlbumAddNewDTO albumAddNewDTO){
            log.debug("开始处理添加相册的请求,参数:{}",albumAddNewDTO);
            albumService.addNew(albumAddNewDTO);
         return JsonResult.ok();
    }

    //http://localhost:9080/albums/1998/delete
    @ApiOperation("删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理根据id删除相册请求,参数{}",id);
        albumService.delete(id);
        return JsonResult.ok();
    }

    //http://localhost:9080/albums/1998/update
    @ApiOperation("修改相册")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult updateInfoById(@PathVariable Long id, AlbumUpdateDTO albumUpdateDTO){
        log.debug("开始处理修改相册基本信息的请求,参数id:{},新数据{}",id,albumUpdateDTO);
        albumService.updateInfoById(id, albumUpdateDTO);
        return JsonResult.ok();
    }

    //http://localhost:9080/albums/1998
    @ApiOperation("根据id查询相册详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult  getStandardById(@PathVariable Long id){
        log.debug("开始处理根据id查询相册详情的请求,参数:{}",id);
        AlbumStandardVO album = albumService.getStandardById(id);

        return JsonResult.ok(album);
    }


    //http://localhost:9080/albums
    @ApiOperation("查询相册列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list(){
        log.debug("开始处理查询相册列表请求,参数:无");
        List<AlbumListItemVO> list = albumService.list();

        return JsonResult.ok(list);
    }


}
